home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 4.0 KB | 148 lines | [TEXT/MPS ] |
- /*
- * File: Service.cp
- *
- * Contains: xxx put contents here xxx
- *
- * Written by: Rick Violet
- *
- * Copyright: © 1992-1994 by Apple Computer, Inc., all rights reserved.
- *
- * Change History (most recent first):
- *
- * <2> 1/27/94 BD String utilities moved to TextUtils.h from Packages.h.
- * <1+> 1/27/94 BD String utilities moved to TextUtils.h from Packages.h.
- * <5+> 11/19/92 RV
- * 11/18/92 RV xxx put comment here xxx
- *
- * To Do:
- */
-
- #ifndef __Service__
- #include "Service.h"
- #endif
-
- #ifndef __Application__
- #include "Application.h"
- #endif
-
- #ifndef __RequestDispatcher__
- #include "RequestDispatcher.h"
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Global Variables
- //—————————————————————————————————————————————————————————————————————————————————————
- extern RequestDispatcher* gTheRequestDispatcher;
- extern Application* gTheApplication;
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Service::Service - constructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- Service::Service( char* pSrvName )
- {
- if( pSrvName != nil )
- {
- fSrvNameText = new char[ strlen( pSrvName ) + 1 ];
- if( fSrvNameText != nil )
- {
- strcpy( fSrvNameText, pSrvName );
- }
- }
- else
- {
- fSrvNameText = nil;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Service::~Service - destructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- Service::~Service()
- {
- if( fSrvNameText != nil )
- {
- delete fSrvNameText;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Service::CanDoService - return true if we can handle the Service indicated.
- //—————————————————————————————————————————————————————————————————————————————————————
- Boolean
- Service::CanDoService( char* pServiceName )
- {
- short tResult;
-
- if( fSrvNameText != nil )
- {
- tResult = relstring( pServiceName, fSrvNameText, false, true );
- if( tResult == 0 )
- {
- return true;
- }
- }
- return false;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Service::ProcessRequest - implement the Request from V.U.
- //
- // This method is called by the Dispatcher to implement the requested service.
- // Override this method within your own subclass to implement the Service.
- // Be sure to call Request::CheckForCancel frequently to allow for canceling.
- // If Request::CheckForCancel returns true, then stop processing, and return
- // immeadiately.
- // Otherwise continue processing.
- //
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Service::ProcessRequest( Request* pReq )
- {
- //———— We do nothing but beep thrice
- SysBeep( 1 );
- SysBeep( 1 );
- SysBeep( 1 );
-
- //———— and return the word 'beeped' to the script
- pReq->SetReturnValue( "beeped" );
-
- //———— no errors encountered
- return noErr;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Service::GetServiceNameText
- //—————————————————————————————————————————————————————————————————————————————————————
- ScriptValue*
- Service::GetServiceNameText()
- {
- VUString* tTextVal;
-
- tTextVal = new VUString( fSrvNameText );
-
- return tTextVal;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Service::CheckForCancel - Check for cancel requests and return true
- // if the current request has been canceled
- //—————————————————————————————————————————————————————————————————————————————————————
- Boolean
- Service::CheckForCancel( Request* pReq )
- {
- Boolean tHasBeenCanceled = false;
-
- //———— Spin the cursor for Humans to see
- gTheApplication->SpinTheCursor();
-
- //———— Reset all TimeOut counters which are due
- gTheRequestDispatcher->ResetAllTimeOutCounters();
-
- //———— Check to see if we have received a Cancel message for this request
- return pReq->HasBeenCanceled();
- }
-